unit uFrmClock;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Oracle, StrUtils, ExtCtrls, MMSystem, oraclemonitor, DateUtils, inifiles, uSQLs,
  MPlayer, ComCtrls, OracleData, Grids, math, umainutils, DB, OnGuard, OgProExe;

type
  TFrmMainClock = class(TForm)
    OracleQuery1: TOracleQuery;
    OracleQueryPrizes: TOracleQuery;
    TimerScrollPrizes: TTimer;
    lbl_TotalChips: TLabel;
    lbl_AvgStack: TLabel;
    lbl_RebuysAllowed: TLabel;
    lbl_AddonsAllowed: TLabel;
    lbl_TournamemntName: TLabel;
    lbl_Players: TLabel;
    lbl_LevelName: TLabel;
    lbl_Blinds: TLabel;
    lbl_Ante: TLabel;
    lbl_RebuyLastRound: TLabel;
    lbl_ThisLevel: TLabel;
    lbl_NextLevel: TLabel;
    lbl_NextLevelName: TLabel;
    lbl_NextBlinds: TLabel;
    lbl_NextAnte: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    Panel8: TPanel;
    Panel9: TPanel;
    Panel10: TPanel;
    lbl_PaidTop: TLabel;
    pnl_NoTournaments: TPanel;
    lbl_Clock: TLabel;
    lbl_PrizeMoney: TLabel;
    lbl_PrizeMoneyValue: TLabel;
    img_Logo: TImage;
    tmr_ClockCountDown: TTimer;
    OracleDataSet1: TOracleDataSet;
    img_Background: TImage;
    lbl_PrizeLvl1: TLabel;
    lbl_PrizeLvl2: TLabel;
    lbl_PrizeLvl3: TLabel;
    lbl_PrizeVal1: TLabel;
    lbl_PrizeVal2: TLabel;
    lbl_PrizeVal3: TLabel;
    stg_Prizes: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure TimerScrollPrizesTimer(Sender: TObject);
    procedure tmr_ClockCountDownTimer(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  private
    PrizeLevelScroll: Integer;
    PreviusRoundIdx, ThisRoundIdx: variant;
    m_TournamentID, m_DisplayTableZone: string;
    TournamentType, RebuysAllowed, AddonsAllowed: string;
    LockClock: boolean;
    StandAlone: boolean;
    { Private declarations }
    procedure SetGUI;
    procedure SetClock();
    function LoadFont(sFontFileName: string; bLoadIt: boolean): boolean;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure SetRegisteringSeatingNextRound(OracleDataSet: TOracleDataSet);
  public
    { Public declarations }
    RoundLevelSA: Integer;
    ClockPaused: boolean;
    PrevClockValue, Clock, PrevClock, ClockSA: TDateTime;
    Ante, PaidTop: string;
    PrizeMoneyValue: string;
    PlayersValue: string;
    TotalChipsValue: string;
    AvgStackValue: string;
    LevelName: string;
    Blinds: string;
    NextLevelName: string;
    NextBlinds: string;
    NextAnte: string;
    TournamemntName: string;
    RebuysAllowedValue: string;
    AddonsAllowedValue: string;
    QueryTimes: Integer;
    PrevScreenHeight: Integer;
    Currency_Symbol: string;
    MainFormWidth: Integer;
    ApplicationStarted, PlaySounds: boolean;
    ColorGeneralData, ColorThisLevel, ColorTournamentData: TColor;
    procedure GetData(OracleDataSet: TOracleDataSet);
    procedure GetClockData(TournamentID: string; DisplayTableZone: string);
    procedure HideTournamentName();
    procedure SetFontColors(ColorTournamentData, ColorThisLevel, ColorGeneralData: TColor);
  end;

var
  FrmMainClock: TFrmMainClock;

const
  ScreenWidth: LongInt = 800; { I designed my form in 800x600 mode. }
  ScreenHeight: LongInt = 600;

implementation

uses uFrmDisplay, uUtils, uFrmClockControl;
{$R *.dfm}

procedure TFrmMainClock.FormResize(Sender: TObject);
var
  AConponent: TComponent;
  i: Integer;
begin
  // stg_Prizes.DefaultRowHeight := Trunc(PrizesRowHeight * (self.ClientHeight / ScreenHeight));
  // left horiz lines
  FrmClockControl.Hide;
  Panel3.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  Panel6.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  Panel7.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  // right horiz lines
  Panel10.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  Panel9.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  Panel8.Width := Trunc(260 * (ClientWidth / ScreenWidth));
  Panel10.Left := Width - Panel10.Width;
  Panel9.Left := Width - Panel9.Width;
  Panel8.Left := Width - Panel8.Width;
  //
  Panel3.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  Panel6.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  Panel7.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  Panel8.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  Panel9.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  Panel10.Height := Trunc(2 * (ClientWidth / ScreenWidth));
  //
  FrmClockControl.stg_Blinds.DefaultRowHeight := (FrmClockControl.stg_Blinds.ClientHeight - FrmClockControl.stg_Blinds.GridLineWidth) div FrmClockControl.stg_Blinds.RowCount;
  FrmClockControl.stg_Blinds.DefaultColWidth := (FrmClockControl.stg_Blinds.ClientWidth - FrmClockControl.stg_Blinds.GridLineWidth) div FrmClockControl.stg_Blinds.ColCount;
  FrmClockControl.CBX_TournamentData.ItemHeight := Trunc(16 * (ClientWidth / ScreenWidth));
  FrmClockControl.CBX_ThisLevel.ItemHeight := Trunc(16 * (ClientWidth / ScreenWidth));
  FrmClockControl.CBX_GeneralData.ItemHeight := Trunc(16 * (ClientWidth / ScreenWidth));
  FrmClockControl.stg_Win.DefaultRowHeight := (FrmClockControl.stg_Win.ClientHeight - FrmClockControl.stg_Win.GridLineWidth) div FrmClockControl.stg_Win.RowCount;
  FrmClockControl.stg_Win.DefaultColWidth := (FrmClockControl.stg_Win.ClientWidth - FrmClockControl.stg_Win.GridLineWidth) div FrmClockControl.stg_Win.ColCount;

end;

procedure TFrmMainClock.GetData(OracleDataSet: TOracleDataSet);
var
  m_TournamentID, RebOrAdd, NextRebOrAdd: string;
  i, k, SelRow, j, max_width1, max_width2: Integer;
  IsBreak, IsBeforeStart: boolean;
begin
  // GET TOURNAMENT ROUNDS FOR THIS TIME
  ThisRoundIdx := '';
  lbl_RebuyLastRound.Visible := false;
  if OracleDataSet = nil then
  begin

  end
  else if not OracleDataSet.Eof then
  begin
    NextLevelName := '';
    NextBlinds := '';
    Ante := '';
    Blinds := '';
    LevelName := '';
    NextAnte := '';
    inc(QueryTimes);
    if QueryTimes > 10 then
    begin
      QueryTimes := 1;
    end;
    IsBreak := StrToB(OracleDataSet.FieldValues['IS_BREAK']);
    IsBeforeStart := StrToB(OracleDataSet.FieldValues['IS_BEFORE_START']);
    if pnl_NoTournaments.Visible then
    begin
      pnl_NoTournaments.Visible := false;
    end;
    m_TournamentID := VarToStr(OracleDataSet.FieldValues['TOURNAMENT_ID']);
    if IsBeforeStart then
    begin
      if abs(PrevClockValue - Clock) > (1 / 24 / 60 / 60 * 1) then // 1 sec
      begin
        Clock := (OracleDataSet.FieldValues['TIME_TO_START']);
      end;
      LevelName := ('STARTING IN');
      if OracleDataSet.FieldValues['STATUS'] = 'REGISTERING' then
      begin
        Blinds := ('REGISTERING') + '...';
        SetRegisteringSeatingNextRound(OracleDataSet);
      end;
      if OracleDataSet.FieldValues['STATUS'] = 'SEATING' then
      begin
        Blinds := ('SEATING') + '...';
        SetRegisteringSeatingNextRound(OracleDataSet);
      end;
    end
    else
    begin
      // REBUY TIME
      RebOrAdd := VarToStr(OracleDataSet.FieldValues['REBUY_OR_ADDON']);
      NextRebOrAdd := VarToStr(OracleDataSet.FieldValues['NEXT_REBUY_OR_ADDON']);
      RebuysAllowed := '';
      AddonsAllowed := '';
      if (RebOrAdd = 'ADDON') then
      begin
        lbl_RebuyLastRound.Visible := true;
        lbl_RebuyLastRound.Caption := ('Addon Time!');
      end;
      if (RebOrAdd = 'REBUY') and (NextRebOrAdd = 'ADDON') then
      begin
        lbl_RebuyLastRound.Visible := true;
        lbl_RebuyLastRound.Caption := ('Last Round for Rebuy!');
      end;
      // ------
      if abs(PrevClockValue - Clock) > (1 / 24 / 60 / 60 * 1) then // 1 sec
      begin
        Clock := (OracleDataSet.FieldValues['TIME_TO_END_ROUND']);
      end;
      ClockPaused := false;
      if 'PAUSED' = OracleDataSet.FieldValues['STATUS'] then
      begin
        ClockPaused := true;
      end;
      if not IsBreak then
      begin
        Blinds := VarToStr(OracleDataSet.FieldValues['SMALL_BLIND']) + '/' + VarToStr(OracleDataSet.FieldValues['BIG_BLIND']);
        LevelName := VarToStr(OracleDataSet.FieldValues['SEQ_INDEX']) + '(' + VarToStr(OracleDataSet.FieldValues['DURATION']) + 'min)';
      end
      else
      begin
        Blinds := 'BREAK' + ' ' + '(' + VarToStr(OracleDataSet.FieldValues['DURATION']) + 'min)'
      end;
      if VarToStr(OracleDataSet.FieldValues['NEXT_DURATION']) <> '' then
      begin
        if VarToStr(OracleDataSet.FieldValues['NEXT_SMALL']) = '' then
        begin
          NextBlinds := ('BREAK') + ' ' + '(' + VarToStr(OracleDataSet.FieldValues['NEXT_DURATION']) + 'min)'
        end
        else
        begin
          NextLevelName := VarToStr(OracleDataSet.FieldValues['SEQ_INDEX'] + 1) + '(' + VarToStr(OracleDataSet.FieldValues['NEXT_DURATION']) + 'min)';
          NextBlinds := VarToStr(OracleDataSet.FieldValues['NEXT_SMALL']) + '/' + VarToStr(OracleDataSet.FieldValues['NEXT_BIG']);
        end;
      end;
      if not IsBreak then
      begin
        if VarToStr(OracleDataSet.FieldValues['ANTE']) <> '' then
        begin
          Ante := VarToStr(OracleDataSet.FieldValues['ANTE']);
        end;
      end;
      if VarToStr(OracleDataSet.FieldValues['NEXT_ANTE']) <> '' then
      begin
        NextAnte := VarToStr(OracleDataSet.FieldValues['NEXT_ANTE']);
      end;
    end;
    ThisRoundIdx := VarToStr(OracleDataSet.FieldValues['SEQ_INDEX']);
    if QueryTimes = 1 then
    begin
      // -----------------------------------------
      // GET TOURNAMENTS
      OracleQuery1.close;
      OracleQuery1.SQL.Clear;
      OracleQuery1.Variables.List.Clear;
      OracleQuery1.SQL.Text := 'SELECT * FROM GET_TOURNAMENT_CLOCK_DATA WHERE ID=' + m_TournamentID;
      OracleQuery1.Execute;
      if not OracleQuery1.Eof then
      begin
        TournamemntName := VarToStr(OracleQuery1.Field('NAME'));
        RebuysAllowedValue := VarToStr(OracleQuery1.Field('REBUYS'));
        AddonsAllowedValue := VarToStr(OracleQuery1.Field('ADDONS'));
        PrizeMoneyValue := FloatToStrF((OracleQuery1.Field('PRIZEMONEY')), ffNumber, 10, 0) + ' ' + Currency_Symbol;
        PlayersValue := VarToStr(OracleQuery1.Field('PLAYERS_TICKETS'));
        TotalChipsValue := FloatToStrF((OracleQuery1.Field('TOTAL_STACK')), ffNumber, 10, 0);
        TournamentType := VarToStr(OracleQuery1.Field('TOU_TYPE_NAME'));
        PaidTop := VarToStr(OracleQuery1.Field('TO_NUM'));
        if OracleQuery1.Field('PLAYING') <> 0 then
        begin
          AvgStackValue := FloatToStrF((OracleQuery1.Field('TOTAL_STACK') div OracleQuery1.Field('PLAYING')), ffNumber, 10, 0);
        end
        else
        begin
          AvgStackValue := FloatToStrF(OracleQuery1.Field('TOTAL_STACK'), ffNumber, 10, 0);
        end;
      end;
      // GET WINING VALUES
      if m_TournamentID <> '' then
      begin
        // GET PRIZES
        OracleQuery1.close;
        OracleQuery1.SQL.Clear;
        OracleQuery1.SQL.Text := 'SELECT * FROM GET_WIN_VALUE WHERE TOURNAMENT_ID=' + m_TournamentID;
        OracleQuery1.Variables.List.Clear;
        OracleQuery1.Execute;
        i := 0;
        while not OracleQuery1.Eof do
        begin
          stg_Prizes.Cells[0, (i)] := IntToStr(i + 1) + '.';
          stg_Prizes.Cells[1, (i)] := VarToStr(OracleQuery1.Field('PLAYER')) + ' ' + FloatToStrF((OracleQuery1.Field('WIN_VALUE')), ffNumber, 10, 0) + ' ' + Currency_Symbol;
          OracleQuery1.next;
          stg_Prizes.RowCount := i;
          inc(i);
        end;
        if i <> 0 then
          k := 3 mod i;
        i := i + k;
        stg_Prizes.RowCount := i;
        stg_Prizes.Row := 0;
      end;
    end;
  end
  else
  begin
    pnl_NoTournaments.Visible := true;
    pnl_NoTournaments.BringToFront;
    pnl_NoTournaments.Align := alClient;
  end;
  SetGUI();
end;

procedure TFrmMainClock.HideTournamentName;
var
  i: Integer;
  AComponent: TComponent;
begin
  for i := 0 to ControlCount - 1 do
  begin
    if Controls[i] is TPanel then
      TPanel(Controls[i]).Top := TPanel(Controls[i]).Top - lbl_TournamemntName.Height + Trunc(lbl_TournamemntName.Height * (TPanel(Controls[i]).Top / self.Height * 1.5));
    if Controls[i] is TLabel then
      TLabel(Controls[i]).Top := TLabel(Controls[i]).Top - lbl_TournamemntName.Height + Trunc(lbl_TournamemntName.Height * (TLabel(Controls[i]).Top / self.Height * 1.5));
    if Controls[i] is TStringGrid then
      TStringGrid(Controls[i]).Top := TStringGrid(Controls[i]).Top - lbl_TournamemntName.Height + Trunc(lbl_TournamemntName.Height * (TStringGrid(Controls[i]).Top / self.Height * 1.5));
    if Controls[i] is TImage then
      TImage(Controls[i]).Top := TImage(Controls[i]).Top - lbl_TournamemntName.Height + Trunc(lbl_TournamemntName.Height * (TImage(Controls[i]).Top / self.Height * 1.5));
  end;
  self.Height := self.Height + 600;
  lbl_TournamemntName.Visible := false;
  {
    if self.Height > 400 then
    begin
    Panel7.Height := 2;
    Panel6.Height := 2;
    Panel3.Height := 2;
    Panel8.Height := 2;
    Panel9.Height := 2;
    Panel10.Height := 2;
    Panel1.Height := 3;
    Panel2.Height := 3;
    Panel4.Width := 3;
    Panel5.Width := 3;
    end
    else
    begin
    Panel7.Height := 1;
    Panel6.Height := 1;
    Panel3.Height := 1;
    Panel8.Height := 1;
    Panel9.Height := 1;
    Panel10.Height := 1;
    Panel1.Height := 2;
    Panel2.Height := 2;
    Panel4.Width := 2;
    Panel5.Width := 2;
    end; }
end;

procedure TFrmMainClock.FormCreate(Sender: TObject);
var
  Res: TResourceStream;
  appINI: TIniFile;
  BackgroundPicture: string;
begin
  if not FileExists('ClockFont.ttf') then
  begin
    Res := TResourceStream.Create(hInstance, 'FONT_CLOCK', Pchar('ANYOL1'));
    Res.SavetoFile('ClockFont.ttf');
    Res.Free;
    AddFontResource(Pchar('ClockFont.ttf'));
    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  end;
  if FrmDisplay <> nil then
  begin
    StandAlone := FrmDisplay.StandAlone;
    Color := clBlack;
  end
  else
  begin
    StandAlone := false;
    Color := $0071A96F;
  end;
  lbl_PrizeLvl1.Caption := '';
  lbl_PrizeLvl2.Caption := '';
  lbl_PrizeLvl3.Caption := '';
  lbl_PrizeVal1.Caption := '';
  lbl_PrizeVal2.Caption := '';
  lbl_PrizeVal3.Caption := '';
  PrizeLevelScroll := 0;
  PrevClockValue := now();
  PrevScreenHeight := -1;
  QueryTimes := 0;
  // Brush.Style := bsClear;
  // BorderStyle := bsNone;
  pnl_NoTournaments.Visible := true;
  pnl_NoTournaments.BringToFront;
  ApplicationStarted := true;
  pnl_NoTournaments.Align := alClient;
  if pct_Temp = nil then
    pct_Temp := TPicture.Create();
  if not StandAlone then
  begin
    RoundLevelSA := 1;
    OracleQueryPrizes.Session := OraSessMainUtils;
    OracleQuery1.Session := OraSessMainUtils;
    img_Logo.Picture := (uUtils.GetImage('select IMAGE, IMAGE_TYPE from SETTINGS where id=1', OraSessMainUtils));
  end
  else
  begin
    RoundLevelSA := 1;
    // FrmClockControl.btn_Pause.Click;
  end;
  appINI := TIniFile.Create(ChangeFileExt(application.ExeName, '.ini'));
  ColorTournamentData := StringToColor(appINI.ReadString('Colors', 'ColorTournamentData', '$00400080'));
  ColorThisLevel := StringToColor(appINI.ReadString('Colors', 'ColorThisLevel', 'clYellow'));
  ColorGeneralData := StringToColor(appINI.ReadString('Colors', 'ColorGeneralData', '$00006600'));
  SetFontColors(ColorTournamentData, ColorThisLevel, ColorGeneralData);
  BackgroundPicture := appINI.ReadString('Other', 'BackGroundPic', '');
  // -----sa settings
  if BackgroundPicture <> '' then
  begin
 //   img_Background.Picture.LoadFromFile(BackgroundPicture);
  end;
  appINI.Free;
  TimerScrollPrizes.Enabled := true;
  img_Logo.Picture.Bitmap.PixelFormat := pf32bit;
  tmr_ClockCountDown.Enabled := true;
  LockWindowUpdate(self.handle);
  Panel7.BringToFront;
  Panel6.BringToFront;
  Panel3.BringToFront;
  Panel8.BringToFront;
  Panel9.BringToFront;
  Panel10.BringToFront;
  Panel1.BringToFront;
  Panel2.BringToFront;
  Panel4.BringToFront;
  Panel5.BringToFront;
  LockWindowUpdate(0);
end;

procedure TFrmMainClock.FormDestroy(Sender: TObject);
begin
  FreeAndNil(pct_Temp);
end;

procedure TFrmMainClock.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if X > (self.Width - FrmClockControl.Width) then
  begin
    if not FrmClockControl.Showing then
      FrmClockControl.Show;
  end
  else
  begin
    if FrmClockControl.Showing then
    begin
      FrmClockControl.Hide;
    end;
  end;
end;

function TFrmMainClock.LoadFont(sFontFileName: string; bLoadIt: boolean): boolean;
var
  sFontRes: string;
begin
  result := true;
  if bLoadIt then
  begin
    { Load the font. }
    if FileExists(sFontFileName) then
    begin
      sFontRes := sFontFileName + #0;
      if AddFontResource(@sFontRes[1]) = 0 then
        result := false
      else
        SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
    end;
  end
  else
  begin
    { Unload the font. }
    sFontRes := sFontFileName + #0;
    result := RemoveFontResource(@sFontRes[1]);
    SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
  end;
end;

procedure TFrmMainClock.CreateParams(var Params: TCreateParams);
Begin
  inherited CreateParams(Params);
  Params.ExStyle := WS_EX_TRANSPARENT;
End;

procedure TFrmMainClock.SetGUI;
begin
  begin
    if StandAlone then
    begin
      pnl_NoTournaments.Visible := false;
    end;
    lbl_TournamemntName.Caption := TournamemntName + ' ' + TournamentType;
    if RebuysAllowedValue <> '' then
    begin
      lbl_RebuysAllowed.Caption := ('Rebuys:') + ' ' + RebuysAllowedValue;
    end
    else
    begin
      lbl_RebuysAllowed.Caption := '';
    end;
    if AddonsAllowedValue <> '' then
    begin
      lbl_AddonsAllowed.Caption := ('Addons:') + ' ' + AddonsAllowedValue;
    end
    else
    begin
      lbl_AddonsAllowed.Caption := '';
    end;
    lbl_PrizeMoneyValue.Caption := PrizeMoneyValue + ' ' + CurrencyString;
    lbl_Players.Caption := ('Players:') + ' ' + PlayersValue;
    lbl_TotalChips.Caption := ('Tot.Chips:') + ' ' + TotalChipsValue;
    lbl_AvgStack.Caption := ('Avg.Chips:') + ' ' + AvgStackValue;
    lbl_LevelName.Caption := ('Level:') + ' ' + LevelName;
    if PaidTop = '' then
      lbl_PaidTop.Caption := ''
    else
      lbl_PaidTop.Caption := ('Paid Top') + ' ' + PaidTop;
    SetClock();
    lbl_Blinds.Caption := ('Blinds:') + Blinds;
    lbl_NextLevelName.Caption := ('Level:') + ' ' + NextLevelName;
    lbl_NextBlinds.Caption := ('Blinds:') + NextBlinds;
    lbl_NextAnte.Caption := ('Ante:') + NextAnte;
    lbl_Ante.Caption := ('Ante:') + Ante;
  end;
end;

procedure TFrmMainClock.SetRegisteringSeatingNextRound(OracleDataSet: TOracleDataSet);
var
  RebOrAdd, NextRebOrAdd: string;
begin
  // REBUY TIME
  NextRebOrAdd := VarToStr(OracleDataSet.FieldValues['REBUY_OR_ADDON']);
  lbl_RebuysAllowed.Caption := ('Rebuys');
  lbl_AddonsAllowed.Caption := ('Addons');
  if (RebOrAdd = 'REBUY') then
  begin
    lbl_RebuysAllowed.Caption := ('Rebuys') + ' ' + ('(YES)');
  end
  else if (NextRebOrAdd = 'ADDON') then
  begin
    lbl_AddonsAllowed.Caption := ('Addons') + ' ' + ('(YES)');
  end;
  lbl_RebuyLastRound.Visible := false;
  ClockPaused := false;
  if 'PAUSED' = OracleDataSet.FieldValues['STATUS'] then
  begin
    ClockPaused := true;
  end;
  NextBlinds := VarToStr(OracleDataSet.FieldValues['SMALL_BLIND']) + '/' + VarToStr(OracleDataSet.FieldValues['BIG_BLIND']);
  NextLevelName := VarToStr(OracleDataSet.FieldValues['SEQ_INDEX']);
  ThisRoundIdx := VarToStr(OracleDataSet.FieldValues['SEQ_INDEX']);
end;

procedure TFrmMainClock.TimerScrollPrizesTimer(Sender: TObject);
var
  VisRows: Integer;
begin
  TimerScrollPrizes.Enabled := false;
  lbl_PrizeLvl1.Caption := stg_Prizes.Cells[0, PrizeLevelScroll];
  lbl_PrizeVal1.Caption := stg_Prizes.Cells[1, PrizeLevelScroll];
  inc(PrizeLevelScroll);
  lbl_PrizeLvl2.Caption := stg_Prizes.Cells[0, PrizeLevelScroll];
  lbl_PrizeVal2.Caption := stg_Prizes.Cells[1, PrizeLevelScroll];
  inc(PrizeLevelScroll);
  lbl_PrizeLvl3.Caption := stg_Prizes.Cells[0, PrizeLevelScroll];
  lbl_PrizeVal3.Caption := stg_Prizes.Cells[1, PrizeLevelScroll];
  inc(PrizeLevelScroll);
  if PrizeLevelScroll >= stg_Prizes.RowCount then
  begin
    PrizeLevelScroll := 0;
  end;
  TimerScrollPrizes.Enabled := true;
end;

procedure TFrmMainClock.SetClock;
var
  ClockStr: string;
begin
  ClockStr := TimeToStr(Clock);
  if leftstr(ClockStr, 1) = '0' then
  begin
    ClockStr := MidStr(ClockStr, 3, Length(ClockStr));
  end;
  if ClockPaused then
  begin
    lbl_Clock.Caption := 'PAUSED';
  end
  else
  begin
    lbl_Clock.Caption := ClockStr;
  end;
  // lbl_Clock.Update;
end;

procedure TFrmMainClock.SetFontColors(ColorTournamentData, ColorThisLevel, ColorGeneralData: TColor);
var
  IniFile: TIniFile;
begin
  IniFile := TIniFile.Create(ChangeFileExt(application.ExeName, '.ini'));
  IniFile.WriteString('Colors', 'ColorTournamentData', ColorToString(ColorTournamentData));
  IniFile.WriteString('Colors', 'ColorThisLevel', ColorToString(ColorThisLevel));
  IniFile.WriteString('Colors', 'ColorGeneralData', ColorToString(ColorGeneralData));
  IniFile.Free;
  lbl_TotalChips.Font.Color := ColorGeneralData;
  lbl_AvgStack.Font.Color := ColorGeneralData;
  lbl_RebuysAllowed.Font.Color := ColorGeneralData;
  lbl_AddonsAllowed.Font.Color := ColorGeneralData;
  lbl_NextLevel.Font.Color := ColorGeneralData;
  lbl_RebuyLastRound.Font.Color := ColorGeneralData;
  lbl_NextLevelName.Font.Color := ColorGeneralData;
  lbl_NextBlinds.Font.Color := ColorGeneralData;
  lbl_NextAnte.Font.Color := ColorGeneralData;
  lbl_PrizeLvl1.Font.Color := ColorGeneralData;
  lbl_PrizeLvl2.Font.Color := ColorGeneralData;
  lbl_PrizeLvl3.Font.Color := ColorGeneralData;
  lbl_PrizeVal1.Font.Color := ColorGeneralData;
  lbl_PrizeVal2.Font.Color := ColorGeneralData;
  lbl_PrizeVal3.Font.Color := ColorGeneralData;
  //
  lbl_PrizeMoney.Font.Color := ColorTournamentData;
  lbl_PrizeMoneyValue.Font.Color := ColorTournamentData;
  lbl_TournamemntName.Font.Color := ColorTournamentData;
  lbl_Players.Font.Color := ColorTournamentData;
  lbl_PaidTop.Font.Color := ColorTournamentData;
  //
  lbl_LevelName.Font.Color := ColorThisLevel;
  lbl_Blinds.Font.Color := ColorThisLevel;
  lbl_Ante.Font.Color := ColorThisLevel;
  lbl_ThisLevel.Font.Color := ColorThisLevel;
  lbl_Clock.Font.Color := ColorThisLevel;
  //
  // panels
  Panel1.Color := ColorTournamentData;
  Panel2.Color := ColorTournamentData;
  Panel3.Color := ColorTournamentData;
  Panel4.Color := ColorTournamentData;
  Panel5.Color := ColorTournamentData;
  Panel6.Color := ColorTournamentData;
  Panel7.Color := ColorTournamentData;
  Panel8.Color := ColorTournamentData;
  Panel9.Color := ColorTournamentData;
  Panel10.Color := ColorTournamentData;
end;

procedure TFrmMainClock.GetClockData(TournamentID: string; DisplayTableZone: string);
begin
  if StandAlone then
  begin
    GetData(nil);
    if not Showing then
      Show;
  end
  else
  begin
    m_TournamentID := TournamentID;
    m_DisplayTableZone := DisplayTableZone;
    OracleDataSet1.Session := OraSessMainUtils;
    OracleDataSet1.close;
    OracleDataSet1.SQL.Clear;
    OracleDataSet1.Variables.List.Clear;
    if (TournamentID <> '') then
    begin
      OracleDataSet1.SQL.Text := 'SELECT * FROM GETPRESENTTOURNAMENTROUNDDATA WHERE TOURNAMENT_ID=' + TournamentID;
    end
    else if DisplayTableZone <> '' then
    begin
      OracleDataSet1.SQL.Text := 'SELECT * FROM GETPRESENTTOURNAMENTROUNDDATA WHERE DISPLAY_TABLE_ZONE_ID=' + DisplayTableZone;
    end;
    if OracleDataSet1.SQL.Text <> '' then
    begin
      OracleDataSet1.Open;
      GetData(OracleDataSet1);
      if not Showing then
        Show;
    end;
  end;
end;

procedure TFrmMainClock.tmr_ClockCountDownTimer(Sender: TObject);
begin
  if not pnl_NoTournaments.Visible then
  begin
    if not ClockPaused then
    begin
      PrevClock := Clock;
      Clock := Clock + (PrevClockValue - now());
    end;
    PrevClockValue := now();
    FrmClockControl.DisplayLevelsSA(RoundLevelSA);
    if (Clock <= 0) then
    begin
      Clock := 0;
      if StandAlone and (Clock <> PrevClock) and (FrmClockControl.stg_Blinds.Cells[0, RoundLevelSA + 1] <> '') then
      begin
        inc(RoundLevelSA);
        FrmClockControl.DisplayLevelsSA(RoundLevelSA);
        Clock := ClockSA;
      end;
      GetClockData(m_TournamentID, m_DisplayTableZone);
    end;
    SetClock();
  end;
  // PLAY SOUNDS
  if PreviusRoundIdx <> ThisRoundIdx then
  begin
    if not ApplicationStarted and PlaySounds then
    begin
      if ThisRoundIdx = '' then
      begin
        sndPlaySound('TournamentEnd.wav', SND_NODEFAULT Or SND_ASYNC);
      end
      else if (PreviusRoundIdx = '') then
      begin
        sndPlaySound('TournamentStart.wav', SND_NODEFAULT Or SND_ASYNC);
      end
      else
      begin
        sndPlaySound('TournamentNewRound.wav', SND_NODEFAULT Or SND_ASYNC);
      end;
    end;
  end;
  PreviusRoundIdx := ThisRoundIdx;
  ApplicationStarted := false;
end;

end.
